<?php
namespace app\admin\controller;
use think\captcha\Captcha;
use think\Controller;


class Login extends Controller{

    public function index()
    {	

        return $this->fetch();
    }

    public function login_do()
    {
    	$code = input('code');
    	$account = input('account');
    	$password = input('password');

    	if($account==""){
			$this->error("账号不能为空");
		}

		if($password==""){
			$this->error("密码不能为空");
		}

    	if(!captcha_check($code))$this->error("验证码有误!");
    	$data = Model('Admin')->index(['account'=>$account]);
    	
    	if(empty($data))$this->error('用户不存在！');

    	$pass_bool = Model('Admin')->verification_hash($password,$data['password']);
    	
    	if(!$pass_bool)$this->error('密码错误！');

    	session("info",$data);
		$l['ip']   = get_client_ip();
		$l['logintime'] = time();
		Model('Admin')->update_value(['account'=>$account],$l);
		$this->success('登录成功');
    }

    public function up_login(){
    	session("info",null);
    }

    public function captchaImg()
	{	$config =    [
			'codeSet'	  =>'1234567890',
		// 验证码字体大小
			'fontSize'    =>    30,
		// 验证码位数
			'length'      =>    4,
		// 关闭验证码杂点
			'useNoise'    =>    true,
	];
		$captcha = new Captcha($config);
		return $captcha->entry();
	}
}
